package edu.mama.college.controller.admin;

import edu.mama.college.model.JsonResult;
import edu.mama.college.model.Page;
import edu.mama.college.model.User;
import edu.mama.college.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/admin")
public class UserController {


    @Autowired
    private UserService userService;

    @GetMapping("/user/list")
    public JsonResult list(@RequestParam(value="page",defaultValue="1") int page,
                           @RequestParam(value="size",defaultValue="10") int size,
                           @RequestParam(value="mobile",required = false) String mobile,
                           @RequestParam(name = "dateRange", required = false) String[] dateRange
                           ){
        String begin = dateRange != null && dateRange.length > 0 ? dateRange[0] : null;
        String end = dateRange != null && dateRange.length > 1 ? dateRange[1] : null;

        Page<User> userPage = userService.userList(page,size,mobile,begin,end);

        return JsonResult.success(userPage);
    }
}
